package com.lucian.requestForWord;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLDecoder;

/**
 * 接收端
 */
public class OtherServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //获取传递过来的值
        String name = (String) req.getParameter("pname");
        //拆封
        //byte[] bytes = name.getBytes("ISO8859-1");

        //解码：  组装
        String decode = URLDecoder.decode(name, "UTF-8");
        System.out.println("==============" + decode);

        //组装
        String page = req.getParameter("page");
        System.out.println(page);
//        int count=0;
//        Enumeration<String> parameterNames = req.getParameterNames();
//        while (parameterNames.hasMoreElements()){
//            String s = parameterNames.nextElement();
//            String parameter = req.getParameter(s);
//            System.out.println(parameter);
//            count++;
//        }
//        System.out.println(count);

        //从域属性中获取数据
//        Object attrname = req.getAttribute("attrname");
//        System.out.println(attrname);


//        Enumeration<String> attributeNames = req.getAttributeNames();
//        while (attributeNames.hasMoreElements()){
//            String s = attributeNames.nextElement();
//            Object attribute = req.getAttribute(s);
//            System.out.println("-----"+attribute);
//
//        }

        PrintWriter writer = resp.getWriter();
        writer.println("This is other");


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        doGet(req, resp);

    }
}
